/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sistemperpustakaan.controller;

import javax.swing.JOptionPane;
import sistemperpustakaan.entity.DendaBuku;
import sistemperpustakaan.model.DendaModel;
import sistemperpustakaan.utility.NumberUtility;
import sistemperpustakaan.view.denda.FrmDendaBuku;

/**
 *
 * @author EKo
 */
public class DendaController {

    DendaModel model;
    DendaBuku dendaBuku;
    FrmDendaBuku dendaBukuView;

    public DendaController(FrmDendaBuku dendaBukuView) {
        this.dendaBukuView = dendaBukuView;
    }

    public DendaController(DendaModel model, FrmDendaBuku dendaBukuView) {
        this.model = model;
        this.dendaBukuView = dendaBukuView;
    }

    public DendaController() {
    }

    public DendaBuku getDendaBuku() {
        return dendaBuku;
    }

    public void setDendaBuku(DendaBuku dendaBuku) {
        this.dendaBuku = dendaBuku;
    }

    public FrmDendaBuku getDendaBukuView() {
        return dendaBukuView;
    }

    public void setDendaBukuView(FrmDendaBuku dendaBukuView) {
        this.dendaBukuView = dendaBukuView;
    }

    public DendaModel getModel() {
        return model;
    }

    public void setModel(DendaModel model) {
        this.model = model;
    }

    public void showDendaBuku() {
        DendaBuku dendaBuku = model.getViewDendaBuku();
//        System.out.println("sampe sini");
        dendaBukuView.getTxtDendaBuku().setText(dendaBuku.getDendaBuku() + "");



    }

    public void UpdateDendaBuku() {
        if (dendaBukuView.getTxtDendaBuku().getText().equals("")) {
            JOptionPane.showMessageDialog(dendaBukuView, "Field Masih kosong");
        }else if (!NumberUtility.isNumberValid(dendaBukuView.getTxtDendaBuku().getText())) {
            JOptionPane.showMessageDialog(dendaBukuView, "Field ini harus diisi dengan angka");
            dendaBukuView.getTxtDendaBuku().requestFocus();
        } else {
            if (model.updateDendaBuku(Integer.valueOf(dendaBukuView.getTxtDendaBuku().getText()))) {
                JOptionPane.showMessageDialog(dendaBukuView, "Setting Denda sukses");
                showDendaBuku();
//                dendaBukuView.dispose();
            } else {
                JOptionPane.showMessageDialog(dendaBukuView, "Setting Denda gagal");
            }
        }
    }
}
